package net.thxjj.adminServer.websocket.mq;

import com.alibaba.fastjson.JSONObject;
import net.thxjj.adminServer.entity.Const;
import net.thxjj.adminServer.util.DateUtil;
import net.thxjj.sitermodel.Device;
import org.apache.commons.lang.StringUtils;

public class JSONOneNet2DeviceUtil {

    public static Device getDeviceFrom(JSONObject jsonObject){

        Device device = new Device();

        //获取创建时间
       String create_time_str = jsonObject.getString("create_time");
        if(!StringUtils.isEmpty(create_time_str)){
            long create_time = DateUtil.getTimeLong(create_time_str);
            device.setCreateTime(create_time);
        }


        //获取最后上线时间
        String last_login_time_str = jsonObject.getString("last_login");
        if(!StringUtils.isEmpty(last_login_time_str)){
            long last_login_time = DateUtil.getTimeLong(last_login_time_str);
            device.setOnlineAt(last_login_time);
        }


        //获取设备名称
        device.setDeviceName(jsonObject.getString("title"));

        //获取设备id
        device.setDeviceId(jsonObject.getString("id"));

        //写死产品id 确保两个平台产品id不一样
        device.setProdKey(Const.ONENET_PRODUCT_ID);

        //获取设备imei
        device.setImei(jsonObject.getString("rg_id"));

        //获取设备imsi
        device.setImsi(jsonObject.getString("imsi"));

        //获取设备网络状态
        boolean flag_online = jsonObject.getBoolean("online");
        if(flag_online){
            device.setNetStatus(1L);
        }else{
            device.setNetStatus(2L);
        }

        return device;
    }
}
